<template>
	<view class="box">
		<view class="item" @click="navTo(`/pages/cats/cats?name=${item.name}`)" :style="[{backgroundImage:`url(${item.pic_url})`}]" v-for="(item,index) in list"
			:key="index">{{item.name}}</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: []
			};
		},
		methods: {
			async getList() {

			},
			async getProduct(id) {
				const res = await this.$request({
					url: this.$api.default.cat_list
				})
				if (res.code == 0) {
					let list = []
					let lists = []
					res.data.list.map(item => list.push(...item.child))
					for (let i = 0; i < list.length; i++) {
						for (let j = i + 1; j < list.length; j++) {
							if (list[i].name == list[j].name) {
								list[j].child.push(...list[i].child);
								// console.log(list[i],list[j],1);
								j = ++i;
							}
						}
						lists.push(list[i]);
					}
					// console.log(list);
					this.list = lists
				}
			},
			navTo(url) {
				uni.navigateTo({
					url
				});
			}
		},
		created() {
			this.getProduct();
		}
	};
</script>

<style lang="scss" scoped>
	.box {
		display: flex;
		flex-wrap: wrap;
		background-color: #f2f2f2;
		padding: 10rpx;
		.item {
			width: calc(33.33% - 20rpx);
			margin: 10rpx;
			// margin-bottom: 20rpx;
			height: 120rpx;
			border-radius: 20rpx;
			color: #fff;
			// font-weight: bold;
			display: flex;
			align-items: center;
			justify-content: center;
			background-position: center;
			background-repeat: no-repeat;
			background-size: cover;
			font-size: 28rpx;
		}
	}
</style>